package behavior.interpreter;

import static behavior.interpreter.AndExpression.FLEX;

/**
 * @author dali
 * @date 2021-07-28 10:29
 * @Description 上下文
 */

public class Context {
    private String[] citys = {"北京", "太原"};
    private String[] persons = {"老人", "孕妇"};
    private Expression expression;
    public Context() {
        Expression city = new TerminalExpression(citys);
        Expression person = new TerminalExpression(persons);
        expression = new AndExpression(city, person);
    }
    public void freeRide(String info) {
        //提示语，可自行设置
        String s1 = "哔！"+info.split(FLEX)[1] + "卡，欢迎乘车，您本次乘车免费！";
        String s2 = "哔！欢迎乘车，您本次乘车扣费2元！";
        System.out.println(expression.interpret(info) ? s1 : s2);
    }
}
